package com.sxt.sys.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * app服务上下文监听（设置上下文）
 * @author WanMing
 * @date 2019/1/30 18:31
 */
@WebListener
public class AppServletContextListence implements ServletContextListener {

    /**
     * 服务器初始化设置全局上下文ctx
     * @param sce
     */
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        ServletContext servletContext = sce.getServletContext();
        String ctx = servletContext.getContextPath();
        servletContext.setAttribute("ctx",ctx);
        System.out.println("上下文创建成功"+ctx+"===========");

    }


    @Override
    public void contextDestroyed(ServletContextEvent sce) {

    }
}
